#ifndef _BUOLA_GUI_X11_CGLXCONTEXT_H_
#define _BUOLA_GUI_X11_CGLXCONTEXT_H_

#include <buola/gui/x11/auto.h>
#include <buola/gl/ccontext.h>
#include <buola/gui/x11/cx11window.h>
#include <buola/gui/x11/cglxinterface.h>

namespace buola { namespace gui { namespace x11 {

DECLARE_NAME(ReferenceContext);
DECLARE_NAME(WithoutWindow);

class CGLXContext : public gl::CContext
{
public:
    CGLXContext(CX11Window *pWindow,bool pDirect=true);
    CGLXContext(NReferenceContext);
    CGLXContext(NWithoutWindow);
    virtual ~CGLXContext();

    virtual img::CSurface *Surface() {   return mWindow;    }
    virtual void MakeCurrent(img::CSurface *pSurface);
    virtual bool IsCurrent();
    virtual void SwapBuffers();

private:
    void DoCreateContext(CGLXContext *pReference,bool pDirect);
    
    CX11Window *mWindow;
    CGLXInterface *mInterface;
    GLXContext mContext;

    static CGLXContext *mReferenceContext;
    static CX11Window *mFakeWindow;
};

/*namespace x11*/ } /*namespace gui*/ } /*namespace buola*/ }

#endif
